Telegram Group & Telegram Channel
Что выведет следующий код на C#?


using System;

class Program {
static void Main() {
int a = 1000;
int b = 1000;

object x = a;
object y = b;

Console.WriteLine(x == y); // #1
Console.WriteLine(x.Equals(y)); // #2
}
}


🔢 Варианты ответа:

A)

True


B)

False


C)

True


D)

False


Правильный ответ: C

💡 Почему?

-
x и y — boxed значения типа int, то есть ссылки на два разных объекта в куче.
-
x == y сравнивает ссылки, а не значения → False.
-
x.Equals(y) вызывает метод Equals для int, который сравнивает значения → True.

📌 Подвох — в различии
== и .Equals() при использовании упакованных типов.

@csharp_ci



tg-me.com/csharp_ci/1336
Create:
Last Update:

Что выведет следующий код на C#?


using System;

class Program {
static void Main() {
int a = 1000;
int b = 1000;

object x = a;
object y = b;

Console.WriteLine(x == y); // #1
Console.WriteLine(x.Equals(y)); // #2
}
}


🔢 Варианты ответа:

A)

True


B)

False


C)

True


D)

False


Правильный ответ: C

💡 Почему?

-
x и y — boxed значения типа int, то есть ссылки на два разных объекта в куче.
-
x == y сравнивает ссылки, а не значения → False.
-
x.Equals(y) вызывает метод Equals для int, который сравнивает значения → True.

📌 Подвох — в различии
== и .Equals() при использовании упакованных типов.

@csharp_ci

BY C# (C Sharp) programming


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/csharp_ci/1336

View MORE
Open in Telegram


C C Sharp programming Telegram | DID YOU KNOW?

Date: |

What is Telegram Possible Future Strategies?

Cryptoassets enthusiasts use this application for their trade activities, and they may make donations for this cause.If somehow Telegram do run out of money to sustain themselves they will probably introduce some features that will not hinder the rudimentary principle of Telegram but provide users with enhanced and enriched experience. This could be similar to features where characters can be customized in a game which directly do not affect the in-game strategies but add to the experience.

A Telegram spokesman declined to comment on the bond issue or the amount of the debt the company has due. The spokesman said Telegram’s equipment and bandwidth costs are growing because it has consistently posted more than 40% year-to-year growth in users.

C C Sharp programming from ye


Telegram C# (C Sharp) programming
FROM USA